import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { VantResolver } from '@vant/auto-import-resolver'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import vue from '@vitejs/plugin-vue'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      resolvers: [VantResolver(), ElementPlusResolver()]
    }),
    Components({
      resolvers: [VantResolver(), ElementPlusResolver()]
    })
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  server: {
    proxy: {
      // '/api': {
      //   target: 'http://172.27.6.139',
      //   changeOrigin: true,
      // },
      '/api': {
        target: 'http://wq.bwstudent.com:7999',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, '')
      },
      '/health':{
        target:'http://172.27.6.139/api',
        changeOrigin:true,  
        rewrite:(path)=>path.replace('/health','')
      },
      '/v3':{
        target:'http://localhost:8090',
        changeOrigin:true,
        rewrite:(path)=>path.replace('/v3','')
      }
    }
  }
})
